#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int calculate(string s) {
        vector<int> ret;
        char ch = '+';
        for (int i = 0; i < s.size();)
        {
            if (s[i] == ' ')i++;
            else if (s[i] >= '0' && s[i] <= '9')
            {
                int num = 0;
                while (i < s.size() && s[i] >= '0' && s[i] <= '9')
                {
                    num = num * 10 + (s[i++] - '0');
                }
                if (ch == '+') ret.push_back(num);
                else if (ch == '-') ret.push_back(-num);
                else if (ch == '*') ret.back() *= num;
                else ret.back() /= num;
            }
            else
            {
                ch = s[i];
                i++;
            }
        }
        int r = 0;
        for (auto e : ret) r += e;
        return r;
    }
};